var app = getApp();
import api from "../../api/api";
import { accountlogin } from "../../api/conf";

Page({
  data: {},
  onLoad: function (options) {},
  onReady: function () {},
  onShow: function () {},
  formSubmit: function (e) {
    var that = this;
    if (e.detail.value.username == "") {
      wx.showToast({
        title: "用户名不能为空",
        icon: "none",
      });
      return;
    } else if (e.detail.value.password == "") {
      wx.showToast({
        title: "密码不能为空",
        icon: "none",
      });
      return;
    }
    wx.showLoading({
      title: "正在登录",
      mask: true,
    });
    var openId = wx.getStorageSync("openId");
    api
      .post("/data/wechat/login", {
        openId: openId,
        username: e.detail.value.username,
        password: e.detail.value.password,
      })
      .then((res) => {
        console.log("登录返回结果", res);
        var data = res.data;
        console.log(data == undefined);
        console.log(data.access_token == undefined);
        if (data == undefined || data.access_token == undefined) {
          wx.showToast({
            title: "密码错误",
            icon: "none",
          });
        } else {
          wx.setStorageSync("token", sdata.access_token);
          wx.switchTab({
            url: "/pages/category/category",
          });
        }
      })
      .catch((res) => {
        wx.showToast({
          title: "密码错误",
          icon: "none",
        });
        wx.hideLoading();
      });
  },
});
